package com.qyer.commons.kafka;

import com.google.common.collect.Maps;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.common.TopicPartition;

import java.util.HashMap;
import java.util.Map;

/**
 * User: Z J Wu Date: 2016/07/22 Time: 15:00 Package: com.qyer.commons.kafka
 */
public class CommitMap {

  private Map<TopicPartition, OffsetAndMetadata> offsetMap = Maps.newConcurrentMap();

  public void put(TopicPartition partition, long currentOffset) {
    offsetMap.put(partition, new OffsetAndMetadata(currentOffset + 1));
  }

  public synchronized Map<TopicPartition, OffsetAndMetadata> getCopy() {
    return new HashMap<>(offsetMap);
  }
}
